package br.usp.ime.dojo.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;

public class DojoMainMenu extends Composite {
	HorizontalPanel hPanel;
	Label userLabel;
	Button logoutButton;
	LogoutListener logoutListener;
	
	DojoMainMenu()
	{
		
		userLabel = new Label("");
		userLabel.addStyleName("dojoPadded");
		logoutButton = new Button("Logout");
		logoutButton.setVisible(false);
		logoutButton.addStyleName("dojoPadded");
		hPanel = new HorizontalPanel();
		hPanel.add(userLabel);
		hPanel.add(logoutButton);
		addHandlers();
		initWidget(hPanel);
	}
	
	
	
	public void onIdentificationSuccess(String userName)
	{
		userLabel.setText(userName);
		logoutButton.setVisible(true);
		this.setVisible(true);
	}
	
	//TODO Insert logout logic here! 
	public void onLogout()
	{
		logoutListener.onLogout();
	}
	
	public void addHandlers()
	{
		logoutButton.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				onLogout();
			}
		});
	}

	public void setLogoutListener(LogoutListener listener) {
		logoutListener = listener;
	}
}
